package com.gs.study.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.gs.study.domain.s.MDBUser;
import com.gs.study.domain.s.MDBUserRepository;
import com.gs.study.util.BaseController;
import com.gs.study.util.ResultJson;

/** 
 * @author gaoshang 
 * @date 创建时间：2018年5月15日 下午2:48:11 
 * @version 1.0 
 * @parameter  
 * @since  
 * @return  
 */
@Controller
@RequestMapping(value="/mdb")
public class MDBController extends BaseController{
	@Autowired
	private MDBUserRepository mdbUserRepository;

	public void setUp() {
		mdbUserRepository.deleteAll();
	}

	@RequestMapping(value="/mdb")
	public void test() throws Exception {

		// 创建三个User，并验证User总数
		mdbUserRepository.save(new MDBUser(1L, "didi", 30));
		mdbUserRepository.save(new MDBUser(2L, "mama", 40));
		mdbUserRepository.save(new MDBUser(3L, "kaka", 50));
		System.out.println( mdbUserRepository.findAll().size());
		// 删除一个User，再验证User总数
		MDBUser u = mdbUserRepository.findOne(1L);
		mdbUserRepository.delete(u);
		System.out.println( mdbUserRepository.findAll().size());
		// 删除一个User，再验证User总数
		u = mdbUserRepository.findByName("mama");
		mdbUserRepository.delete(u);
		System.out.println( mdbUserRepository.findAll().size());
		ResultJson json=new ResultJson(true);
		printString(json.toJSONString());
	}
}
